<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script>
    var arr = new Array(1,2,3,4);
    console.log(arr);
    var arr1 = [5,6,7,8];
    console.log(arr1);

    //访问一个元素
    console.log(arr1[2]);//7

    arr1[2] = 100;
    console.log(arr1[2]);

    console.log(arr1[5]);//undefined


    arr1[2] = "张三";
    console.log(arr1[2]);

    arr1[5] = "李四";
    console.log(arr1[5]);

    //遍历数组
    for (let i = 0; i < arr1.length; i++) {
        console.log(arr1[i]);
    }

    //push函数:给数组添加元素，也就是在数组的结尾添加元素。
    var arr2 = [1,3,5];
    arr2.push(8);
    console.log(arr2);

    //splice函数:删除元素
    var arr3 = [1,2,3,4,5];
    arr3.splice(0,3);//从索引为0开始删除，删除3个元素
    console.log(arr3);

</script>
</html>
